require 'rubygems'
gem 'soap4r'
require 'soap/wsdlDriver'
require 'soap/header/simplehandler'
require 'defaultDriver.rb'
require 'authStub.rb'

#Async create options
#options = CreateOptions.new(nil,nil,nil,nil,nil,nil,nil,nil,'Asynchronous')
options = nil

file = IO.readlines("ShipTimes-w-ZipCode.txt")
hdr = String.new
ttlRows = file.length
ttlRowsToSend = 500
procTo = ttlRowsToSend
ttlToSend = ttlRows > ttlRowsToSend ? ttlRowsToSend : ttlRows 
rows = Array.new

file.each_with_index do |line, i|

  columns = Array.new

  if i == 0 then
    hdr = line.split(",").collect! {|h| h.to_s }
  else
    items = line.split(",").collect! {|n| n.to_s }
    items.each_with_index do |items, c|
      columns.push(APIProperty.new(hdr[c].chomp,items.chomp))
    end
  end

  if i == procTo or i == (ttlRows - 1) then
    rows.push(DataExtensionObject.new(nil,nil,nil,nil,nil,nil,nil,'ShipTimes-API',nil,nil,nil,[*columns]))
    resp = $driver.create(CreateRequest.new(options,[*rows]))
    rows.clear
    procTo = i != ttlRows ? procTo + ttlRowsToSend : nil
  else
    rows.push(DataExtensionObject.new(nil,nil,nil,nil,nil,nil,nil,'ShipTimes-API',nil,nil,nil,[*columns]))
  end
end